package zheezes.protocol.impl.gbw.format;

import java.util.Calendar;

public class DataForm23 extends DataForm {
	public static final int SIZE = 2;
	
	private Calendar cal = Calendar.getInstance();
	
	public DataForm23() {
		cal.set(Calendar.MILLISECOND, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.HOUR, 0);
	}
	
	@Override
	public int sizeof() {
		return SIZE;
	}

	@Override
	public int getBytes(byte[] buf, int offset) {
		int idx = offset;
		buf[idx++] = DateFormat.get(cal, Calendar.DATE);
		buf[idx++] = DateFormat.get(cal, Calendar.MONTH);
		
		return idx - offset;
	}

	@Override
	public int setBytes(byte[] buf, int offset) {
		int idx = offset;
		DateFormat.set(cal, Calendar.DATE, buf[idx++]);
		DateFormat.set(cal, Calendar.MONTH, buf[idx++]);
		
		return idx - offset;
	}

	public Calendar getCal() {
		return cal;
	}

	public void setCal(Calendar cal) {
		this.cal = cal;
	}
}